<template>
  <div>
    首页
<!--<button @click="toLogin">按钮 </button>-->
  </div>
</template>

<script>
  import {UserFindAll} from "../../../api/data"
  export default {
    name: 'home',
    components: {},
    data() {
      return {
        formLeft: {
          id: '',
          userName: '',
          userPassword: '',
          randomNo: '',
        },

      }
    },
    mounted() {
    },
    created(){//页面加载就调用方法判断
      this.toLogin();
    },
    methods: {
      toLogin(){
        var PermissionIds = localStorage.getItem('permissionIds');
      //  console.log(PermissionIds)
        //获取当前的cookie
        var cok=document.cookie;
       // console.log(cok);
        if( cok==undefined || cok == ""){
          //移除当前cookie，跳转回登录页面
          this.$cookies.remove("loginUser");
          this.$router.push("/login");
          //清除localStorage保存对象的全部数据
          localStorage.clear();
         // console.log('身份失效,请重新登录')
          // alert("身份失效，请重新登录!");
        }else {
          let username= localStorage.getItem('username');
          let password= localStorage.getItem('password');
          let par = {
            userName: username,
            userPassword: password
          }
          UserFindAll(par).then(res => {
            if (res.data.code != 0) {
              this.$Message.error(res.data.msg)
            }else {
              this.formLeft=res.data.data;
              if (this.formLeft.randomNo !== PermissionIds){
                this.$cookies.remove("loginUser");
                this.$router.push("/login");
                localStorage.clear();
             //   alert("身份失效，请重新登录!");
              }
            }
          });
        }
      }
    }
  }
</script>

<style lang="less">
  .count-style {
    font-size: 50px;
  }

  .title-style {
    font-size: 18px;
    color: #262626;
    font-weight: 500;
    padding: 6px
  }
</style>
